package com.skillscompetition.skillscompetition.controller;


import com.github.pagehelper.PageInfo;
import com.skillscompetition.skillscompetition.bean.SkillScontest;
import com.skillscompetition.skillscompetition.common.ResponseType;
import com.skillscompetition.skillscompetition.service.impl.SkillScontestServiceImpl;
import com.skillscompetition.skillscompetition.vo.SkillSOperrationVo;
import com.skillscompetition.skillscompetition.vo.SkillScontestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 技能表 前端控制器
 * </p>
 *
 * @author lwg
 * @since 2019-11-09
 */
@RestController
@RequestMapping("/skillscontest")
public class SkillScontestController {

    @Autowired
    private SkillScontestServiceImpl skillscontestService;

    /*查询填写理论成绩*/
    @GetMapping("/list")
    public Map<String, Object> getList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                       @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize,
                                       @RequestParam(value = "sort", required = false) String sort) {
        Map<String, Object> map = new HashMap<>();
        PageInfo<SkillScontestVo> exam = skillscontestService.getExam(page, pageSize, sort);
        return ResponseType.success(exam);
    }

    /*填写理论成绩*/
    @PutMapping()
    public Map<String, Object> updateTheorys(@RequestBody List<SkillScontestVo> theorys) {
        try {
            skillscontestService.updateTheorys(theorys);
            return ResponseType.success(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseType.fail();
        }
//      return null;
    }

    /*查询现场操作信息*/
    @GetMapping("operationlist1")
    public Map<String, Object> getSkillSOperation1(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "sort", required = false) String sort) {


        return ResponseType.success(skillscontestService.getSkillSOperation1(page, pageSize, sort));
    }

    /*保存现场操作信息*/
    @PutMapping("operation")
    public Map<String, Object> saveSkillSOperation1(@RequestBody List<SkillScontest> operration) {
        return ResponseType.success(skillscontestService.saveSkillSOperation(operration));
    }

    //总体成绩查询
    @GetMapping("massing")
    public Map<String, Object> massingList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {

        Map<String, Object> map = new HashMap<>();
        PageInfo<SkillScontest> exam = skillscontestService.massingList(page, pageSize);
        return ResponseType.success(exam);
    }

    /**
     * 总统成绩刷新
     *
     * @return
     */
    @GetMapping("refresh")

    public Map<String, Object> refresh() {
        skillscontestService.refresh();
        return ResponseType.success(null);
    }

    /*总成绩导出*/
    @GetMapping("export")
    public void export(HttpServletResponse response) {
        skillscontestService.export(response);
    }

}
